package com.kk.xhr.model.dao;

import static com.kk.xhr.model.dao.RecruitDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.*;

import com.kk.xhr.model.entity.Recruit;
import java.util.List;
import java.util.Optional;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

@Mapper
public interface RecruitMapper {
    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit")
    BasicColumn[] selectList = BasicColumn.columnList(id, title, remark, positionId, endDate, passNum, total, form, status, created, updated);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit")
    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit")
    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="record.id", before=false, resultType=Long.class)
    int insert(InsertStatementProvider<Recruit> insertStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("RecruitResult")
    Optional<Recruit> selectOne(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="RecruitResult", value = {
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="title", property="title", jdbcType=JdbcType.VARCHAR),
        @Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR),
        @Result(column="position_id", property="positionId", jdbcType=JdbcType.BIGINT),
        @Result(column="end_date", property="endDate", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="pass_num", property="passNum", jdbcType=JdbcType.INTEGER),
        @Result(column="total", property="total", jdbcType=JdbcType.INTEGER),
        @Result(column="form", property="form", jdbcType=JdbcType.TINYINT),
        @Result(column="status", property="status", jdbcType=JdbcType.TINYINT),
        @Result(column="created", property="created", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="updated", property="updated", jdbcType=JdbcType.TIMESTAMP)
    })
    List<Recruit> selectMany(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit")
    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, recruit, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, recruit, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit")
    default int deleteByPrimaryKey(Long id_) {
        return delete(c -> 
            c.where(id, isEqualTo(id_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit")
    default int insert(Recruit record) {
        return MyBatis3Utils.insert(this::insert, record, recruit, c ->
            c.map(title).toProperty("title")
            .map(remark).toProperty("remark")
            .map(positionId).toProperty("positionId")
            .map(endDate).toProperty("endDate")
            .map(passNum).toProperty("passNum")
            .map(total).toProperty("total")
            .map(form).toProperty("form")
            .map(status).toProperty("status")
            .map(created).toProperty("created")
            .map(updated).toProperty("updated")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit")
    default int insertSelective(Recruit record) {
        return MyBatis3Utils.insert(this::insert, record, recruit, c ->
            c.map(title).toPropertyWhenPresent("title", record::getTitle)
            .map(remark).toPropertyWhenPresent("remark", record::getRemark)
            .map(positionId).toPropertyWhenPresent("positionId", record::getPositionId)
            .map(endDate).toPropertyWhenPresent("endDate", record::getEndDate)
            .map(passNum).toPropertyWhenPresent("passNum", record::getPassNum)
            .map(total).toPropertyWhenPresent("total", record::getTotal)
            .map(form).toPropertyWhenPresent("form", record::getForm)
            .map(status).toPropertyWhenPresent("status", record::getStatus)
            .map(created).toPropertyWhenPresent("created", record::getCreated)
            .map(updated).toPropertyWhenPresent("updated", record::getUpdated)
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit")
    default Optional<Recruit> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, recruit, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit")
    default List<Recruit> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, recruit, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit")
    default List<Recruit> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, recruit, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit")
    default Optional<Recruit> selectByPrimaryKey(Long id_) {
        return selectOne(c ->
            c.where(id, isEqualTo(id_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, recruit, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit")
    static UpdateDSL<UpdateModel> updateAllColumns(Recruit record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(title).equalTo(record::getTitle)
                .set(remark).equalTo(record::getRemark)
                .set(positionId).equalTo(record::getPositionId)
                .set(endDate).equalTo(record::getEndDate)
                .set(passNum).equalTo(record::getPassNum)
                .set(total).equalTo(record::getTotal)
                .set(form).equalTo(record::getForm)
                .set(status).equalTo(record::getStatus)
                .set(created).equalTo(record::getCreated)
                .set(updated).equalTo(record::getUpdated);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(Recruit record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(title).equalToWhenPresent(record::getTitle)
                .set(remark).equalToWhenPresent(record::getRemark)
                .set(positionId).equalToWhenPresent(record::getPositionId)
                .set(endDate).equalToWhenPresent(record::getEndDate)
                .set(passNum).equalToWhenPresent(record::getPassNum)
                .set(total).equalToWhenPresent(record::getTotal)
                .set(form).equalToWhenPresent(record::getForm)
                .set(status).equalToWhenPresent(record::getStatus)
                .set(created).equalToWhenPresent(record::getCreated)
                .set(updated).equalToWhenPresent(record::getUpdated);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit")
    default int updateByPrimaryKey(Recruit record) {
        return update(c ->
            c.set(title).equalTo(record::getTitle)
            .set(remark).equalTo(record::getRemark)
            .set(positionId).equalTo(record::getPositionId)
            .set(endDate).equalTo(record::getEndDate)
            .set(passNum).equalTo(record::getPassNum)
            .set(total).equalTo(record::getTotal)
            .set(form).equalTo(record::getForm)
            .set(status).equalTo(record::getStatus)
            .set(created).equalTo(record::getCreated)
            .set(updated).equalTo(record::getUpdated)
            .where(id, isEqualTo(record::getId))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: recruit")
    default int updateByPrimaryKeySelective(Recruit record) {
        return update(c ->
            c.set(title).equalToWhenPresent(record::getTitle)
            .set(remark).equalToWhenPresent(record::getRemark)
            .set(positionId).equalToWhenPresent(record::getPositionId)
            .set(endDate).equalToWhenPresent(record::getEndDate)
            .set(passNum).equalToWhenPresent(record::getPassNum)
            .set(total).equalToWhenPresent(record::getTotal)
            .set(form).equalToWhenPresent(record::getForm)
            .set(status).equalToWhenPresent(record::getStatus)
            .set(created).equalToWhenPresent(record::getCreated)
            .set(updated).equalToWhenPresent(record::getUpdated)
            .where(id, isEqualTo(record::getId))
        );
    }
}